#mingw32-64 makefile
#####################################################
target := MineSweeper.exe
target_test := MineSweeper_test.exe
project_path := src
test_path := test
painterengine_path := lib\PainterEngine
cutest_path := lib\cutest
#####################################################

project_build := $(wildcard $(project_path)/*.c)
project_build_o := $(patsubst %.c,%.o,$(project_build))

test_build := $(wildcard $(test_path)/*.c)
test_build_o := $(patsubst %.c,%.o,$(test_build))

painterengine_build_core := $(wildcard $(painterengine_path)/core/*.c)
painterengine_build_painterengine_o := $(patsubst %.c,%.o,$(painterengine_build_core))

painterengine_build_kernel := $(wildcard $(painterengine_path)/kernel/*.c)
painterengine_build_painterengine_o += $(patsubst %.c,%.o,$(painterengine_build_kernel))

painterengine_build_architecture := $(wildcard $(painterengine_path)/architecture/*.c)
painterengine_build_painterengine_o += $(patsubst %.c,%.o,$(painterengine_build_architecture))

painterengine_build_platform := $(wildcard $(painterengine_path)/platform/windows/*.c)
painterengine_build_painterengine_o += $(patsubst %.c,%.o,$(painterengine_build_platform))

painterengine_build_platform := $(wildcard $(painterengine_path)/platform/windows/*.cpp)
painterengine_build_painterengine_o += $(patsubst %.cpp,%.o,$(painterengine_build_platform))

cutest_build := $(wildcard $(cutest_path)/*.c)
cutest_build_o += $(patsubst %.c,%.o,$(cutest_build))

include_path = include

all:$(project_build_o)  $(painterengine_build_painterengine_o) 
	gcc $(project_build_o) $(painterengine_build_painterengine_o) \
	-o $(project_path)\..\$(target) \
	-I "$(painterengine_path)" \
	-I "$(project_path)" \
	-I "$(painterengine_path)\platform\windows" \
	-I "$(include_path)" \
	-L. -lwinmm -ld2d1 -lws2_32 -ldsound -lcomdlg32 -std=c99
	mingw32-make clean
	
	

$(project_path)/%.o:$(project_path)/%.c
	gcc -c $^ -o $@ -I "$(painterengine_path)" -I "$(painterengine_path)/platform/windows" -I "$(include_path)"  -std=c99

$(painterengine_path)/architecture/%.o:$(painterengine_path)/architecture/%.c 
	gcc -c $^ -o $@ -I "$(painterengine_path)" -std=c99

$(painterengine_path)/kernel/%.o:$(painterengine_path)/kernel/%.c
	gcc -c $^ -o $@ -std=c99

$(painterengine_path)/core/%.o:$(painterengine_path)/core/%.c
	gcc -c $^ -o $@ -std=c99

$(painterengine_path)/platform/windows/%.o:$(painterengine_path)/platform/windows/%.c
	gcc -c $^ -o $@ -I "$(project_path)" -I "$(painterengine_path)" -I "$(painterengine_path)/platform/windows" -std=c99

$(cutest_path)/%.o:$(cutest_path)/%.c
	gcc -c $^ -o $@ -std=c99

$(test_path)/%.o:$(test_path)/%.c
	gcc -c $^ -o $@ -I "$(painterengine_path)" -I "$(include_path)" -I "$(cutest_path)" -I "$(project_path)" -std=c99

.PHONY:clean
clean:
	-del /s  "$(painterengine_path)\core\*.o"
	-del /s  "$(painterengine_path)\kernel\*.o"
	-del /s  "$(painterengine_path)\architecture\*.o"
	-del /s  "$(painterengine_path)\platform\windows\*.o"
	-del /s  "$(project_path)\*.o"
	-del /s  "$(test_path)\*.o"

.PHONY:test
test:$(project_build_o)  $(painterengine_build_painterengine_o)  $(cutest_build_o) $(test_build_o)
	gcc $(test_build_o) $(project_build_o) $(painterengine_build_painterengine_o) $(cutest_build_o) \
	-o $(project_path)\..\$(target_test) \
	-I "$(painterengine_path)" \
	-I "$(project_path)" \
	-I "$(painterengine_path)\platform\windows" \
	-I "$(include_path)" \
	-L. -lwinmm -ld2d1 -lws2_32 -ldsound -lcomdlg32 -std=c99
	mingw32-make clean